package com.xca.znb.presenter;

import com.xca.znb.contact.UserAuthView;
import com.xca.znb.model.imodel.UserAuthModel;

public class UserAuthPresenter {
    private UserAuthModel userAuthModel;
    private UserAuthView userAuthView;

    public UserAuthPresenter(UserAuthModel model, UserAuthView view) {
        this.userAuthModel = model;
        this.userAuthView = view;
    }

    public void login(String phone, String password , double num , String type , String time_day , String time_sec) {
        if (userAuthModel.isUserExists(phone)) {
            if (userAuthModel.isValidPassword(phone, password)) {
                userAuthView.navigateToHome();
               // userAuthView.hideLoading();
            } else {
                userAuthView.showError("密码错误");
            }
        } else {
            userAuthModel.addUser(phone, password);
            userAuthView.showError("账号不存在，已注册");
            userAuthModel.addAccount(phone, num, type, time_day, time_sec);
        }
        userAuthView.hideLoading();
    }
    public boolean isUserExists(String phone){
       return userAuthModel.isUserExists(phone);
    }
    public boolean isValidPassword(String phone , String password){
        return userAuthModel.isValidPassword(phone, password);
    }
    public void sign(String phone , String password){
        userAuthModel.addUser(phone, password);
    }

}